<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>鼠标控制小鸟移动</title>
  <style>
    body {
      margin: 0;
    }

    img {
      width: 100px;
      border: 1px solid red;
      position: absolute;
    }
  </style>
</head>

<body>
  <img src="./images/xn.png" alt="" id="myImg">
  <script>
    // 需求: 鼠标移动时, 让小鸟图片跟着鼠标移动

    // 防抖  节流

    let myImg = document.querySelector("#myImg");

    let flag = true
    document.onmousemove = function (e) {
      if (flag) {
        // 获取到鼠标的位置信息
        console.log(e.pageX, e.pageY)

        myImg.style.left = e.pageX + 'px'
        myImg.style.top = e.pageY + 'px'

        flag = false

        setTimeout(() => {
          flag = true
        }, 30)
      }
    }
  </script>
</body>

</html>